﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.MySQL;

namespace IrisanNHS
{
    public partial class Form8 : Form
    {
        MySQL_Database MyDB = new MySQL_Database();

        public Form8()
        {
            InitializeComponent();
            btnReg.Click += new EventHandler(btnReg_Click);
        }

        void btnReg_Click(object sender, EventArgs e)
        {
            if (txtname.Text == "" || txtuser.Text == "" || txtpass.Text == "")
            {
                MessageBox.Show("Complete the field");
                txtname.Focus();
                return;
            }
            else if (txtconfirm.Text == "")
            {
                MessageBox.Show("Confirm your password");
                txtconfirm.Focus();
                return;
            }
            else if (txtconfirm.Text != txtpass.Text)
            {
                MessageBox.Show("Password not match");
                txtconfirm.Focus();
                return;
            }
            else if (cbPosition.SelectedIndex == -1)
            {
                MessageBox.Show("Select your designated position");
                return;
            }

            {
                MyDB.Connection_Database("SELECT * FROM tblusers");
                Information info = new Information();
                info.name = txtname.Text;
                info.user = txtuser.Text;
                info.pass = txtpass.Text;
                txtconfirm.Clear();
                info.position = cbPosition.Text;
                MyDB.Register(info);
                txtname.Clear();
                txtuser.Clear();
                txtpass.Clear();
                cbPosition.SelectedIndex = -1;
                MessageBox.Show("Successfully Registered");
            }   
        }
    }
}
